Thread: Makefile problem when adding dependencies

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    74

    Makefile problem when adding dependencies

    Hi,

    I am a beginner in writing makefiles. I am having some problem compiling an application using Makefile.

    I have two directories, that are at the same level.
    1: TEST, in which resides the application that I have written,
    2: PROJECT_DIRECTORY, is an existing project with a nested directory structure.

    my Makefile resides in TEST.

    my application needs to access some functions defined in a file called M_Example.h. M_Example.c and M_Example.h both reside in
    Code:
    PROJECT_DIRECTORY/some_dir_1/some_dir_2/some_dir_3/some_dir_4
    Now, independently of TEST, I can compile PROJECT_DIRECTORY successfully and the compilation process generates .o files and .a files. My understanding is that these are the libraries at each level and could be used as such in the Makefile. For example, after compilation, I have
    Code:
     M_Example.o
    at the location
    Code:
    PROJECT_DIRECTORY/some_dir_1/some_dir_2/some_dir_3/some_dir_4
    So, here is how my makefile looks

    Code:
    APP_PATH=./
    INCLUDE_PATH=./
    PROJECT_CORE_PATH=../PROJECT_DIRECTORY/some_dir_1/some_dir_2/some_dir_3/some_dir_4
    
    PROJECT_INCLUDE_PATH = $(PROJECT_CORE_PATH)
    
    WARNINGS = -Wall
    
    APP_SOURCES=$(wildcard $(APP_PATH)/*.c)
    APP_HEADERS=$(wildcard $(APP_PATH)/*.h)
    PROJECT_LIBS=$(wildcard $(PROJECT_CORE_PATH)/*.o)
    PROJECT_HEADERS=$(wildcard $(PROJECT_CORE_PATH)/*.h)
    
    vpath %.c $(APP_SOURCES)
    vpath %.h $(APP_HEADERS) $(PROJECT_HEADERS)
    vpath %.o $(PROJECT_LIBS)
    
    
    all : hello
    
    hello : my_string_help.o 
    
    my_string_help.o : my_string_help.c $(APP_HEADERS) $(PROJECT_HEADERS) $(PROJECT_LIBS)
    	gcc -c my_string_help.c 
    
    clean:
    	rm -f my_string_help.o hello
    This is very basic file, my_string_help.c resides in folder TEST, and uses a function from PROJECT_DIRECTORY. I just need to make sure that it can link without errors, but I get the following error when I run "make".


    gcc -c my_string_help.c
    my_string_help.c:2:22: error: M_Example.h: No such file or directory
    make: *** [my_string_help.o] Error 1

    thanks,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Random tutorial.
    Makefile Tutorial

    Setting vpath only enables the makefile to determine the location of dependencies.

    You also need to typically set CFLAGS with appropriate -I paths to also tell the compiler where to find header files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    74
    thanks Salem, that helped.
    the problem is solved.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile dependencies
    By taurus in forum C Programming
    Replies: 1
    Last Post: 11-09-2008, 12:17 AM
  2. Dependencies problem
    By Malek in forum C++ Programming
    Replies: 9
    Last Post: 01-18-2003, 09:21 PM
  3. Problem with #include dependencies
    By QuestionC in forum C Programming
    Replies: 2
    Last Post: 05-25-2002, 10:25 PM
  4. makefile dependencies (again)
    By *ClownPimp* in forum Linux Programming
    Replies: 2
    Last Post: 05-06-2002, 03:13 AM
  5. makefile dependencies
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 05-01-2002, 11:33 AM